#pragma once
#include "../BondMarketStream.h"
#include "IRealTimeDealModel.h"

namespace detail {
class RealTimeDealStat {
  typedef int IndexId;  // MarketStreamInfo.m_indexID/报价序号，日内自增
  typedef MarketStreamRec StatType;
  typedef std::map<std::string, StatType> StatTypeMap;
  typedef std::map<IndexId, std::string>
      IndexIdMap;  // MarketStreamInfo.m_indexID,MarketStreamInfo.m_body.m_id
  StatTypeMap m_stats;
  IndexIdMap m_indexes;  // 用于去重,IDB里面操作作废成交,会产生2条作废成交消息
 public:
  RealTimeDealStat();
  const StatTypeMap& GetStats() const { return m_stats; }
  void AddStatMap(const RealTimeDealStat* pStatMap);
  void AddStat(const MarketStreamInfo& info);
  void UpdateStat(const MarketStreamInfo& oldInfo,
                  const MarketStreamInfo& info);
  void EraseStat(const MarketStreamInfo& info, bool bfound);
  bool GetStat(const std::string& combBondKey, StatType& stat) const;

 protected:
  bool CheckIndexId(int indexId, const char* id);
  RealTimeDealStat::StatType* GetOrCreate(const MarketStreamInfo& info);
};

}  // namespace detail
